using System;
using System.Collections.Generic;
using Sustainalytics.MongoDB.Extensions;

namespace Sustainalytics.Synchronization.Validation.Internals
{
    public static class ValidationMongoCollectionFactory
    {
        public static ValidationMongoCollection<T> GetCollectionFromDatabase<T>(
            Dictionary<string, string> currentConnectionStrings,
            Dictionary<string, string> oldConnectionStrings,
            Func<Dictionary<string, string>, string> getDatabaseName,
            string collectionName = null)
        {
            var oldConnectionString = getDatabaseName.Invoke(oldConnectionStrings);
            var currentConnectionString = getDatabaseName.Invoke(currentConnectionStrings);

            return new ValidationMongoCollection<T>
                       {
                           OldCollection =
                               MongoFactory.GetCollectionFromDatabase<T>(
                                   oldConnectionString,
                                   collectionName),
                           CurrentCollection =
                               MongoFactory.GetCollectionFromDatabase<T>(
                                   currentConnectionString,
                                   collectionName)
                       };
        }
    }
}